﻿<cfscript>
/** 
* @hint "systemManager - message"
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.senate.messageListener" 
	output=false 
	depends="sessionAdvice,securityAdvice"
	{
		
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 

	/**
	*@hint "添加信息"
	*/
	public void function addMessage() output=false {
		
		var userId = sessionAdvice.getAutherUserID();
		var ip = securityAdvice.getIP();
		
		var dateCreate = dateFormat(now(),"YYYY-MM-DD") & " " & timeFormat(now(), "HH:MM:SS");
		
		var targetId = event.getArg("userID");
		var title = event.getArg("subject");
		var describe = event.getArg("Describe");
		
		var isreply = event.getArg("isReply");
		
		var sql = "";
		var queryObj = "";
		
		
		/* Every SQL operation is TRANSACATION*/
		transaction{
			
	
				
				sql = "INSERT INTO t_message(
							id, user_id, target_id, user_content, re_content,
							user_time, re_time, user_ip, target_ip, user_state, target_state, title, isreplay 
						)VALUES(
							seq_message.nextval, :userId, :targetId, :content, '', :userTime, 
							'', :userIp, '', '1', '0', :title, :isreply 
						)
";
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="userId", value=userId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="targetId", value=targetId, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="content", value=describe, cfsqltype="cf_sql_clob" );
				queryObj.addParam( name="userTime", value=dateCreate, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="userIp", value=ip, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="title", value=title, cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="isreply", value=isreply, cfsqltype="cf_sql_char" );
				
				queryObj.execute( sql=sql );
				
				event.setArg("dict", "success");
		}
	}
	
	

}

</cfscript>